students = []

def add_stu():
    student = {}
    new_name = input('请输入姓名:')
    new_tel = input('请输入手机号:')
    new_qq = input('请输入QQ:')
    student['name'] = new_name
    student['tel'] = new_tel
    student['qq'] = new_qq
    students.append(student)
    return students

def remove_stu():
    num = input('请输入要删除的序号:')
    del students[int(num)]
    return students

def revise_stu():
    num = input('请输入要修改的序号:')
    re_name = input('请输入新的姓名:')
    re_tel = input('请输入新的手机号:')
    re_qq = input('请输入新QQ:')
    students[int(num)]['name'] = re_name
    students[int(num)]['tel'] = re_tel
    students[int(num)]['qq'] = re_qq
    return students

def query_stu():
    query_name = input('请输入要查询的学生姓名:')
    count = 0
    for student in students:
        if query_name == student['name']:
            count += 1
            print(student)
    if count == 0:
        print('没有您要找的信息')

def save_data():
    file = open('data.txt', 'w')
    for student in students:
        file.write(student['name'] + ' ' + student['tel'] + ' ' + student['qq'] + '\n')
    file.close()

def restore_data():
    students = []
    lines = open('data.txt').readlines()
    for line in lines:
        name, tel, qq = line.split(' ')
        students.append({'name':name, 'tel':tel, 'qq':qq})

print("******学生管理系统V1.0******")
print('1:添加学生')
print('2:删除学生')
print('3:修改学生')
print('4:查询学生')
print('5:显示所有学生')
print('6:保存数据')
print('7:退出系统')
print('__________________________')
while True:
    num = input('请输入功能选项:')
    if num == '1':
        students = add_stu()
    elif num == '2':
        students = remove_stu()
    elif num == '3':
        students = revise_stu()
    elif num == '4':
        query_stu()
    elif num == '5':
        for student in students:
            print(student)
    elif num == '6':
        save_data()
    elif num == '7':
        exit()
    else:
        print('您输入的选项不存在，请重新输入！')



